<?php

include_once ('../../__global.php');
class commentme extends ml_controller 
{
    private $page = 1;
    private $pagesize = 20;
    
    private $_uids;
    private $_pic_ids;
    private $_nicks;
    private $_personUrls;
    private $_personPics;
    private $_goodUrls;
    private $_pic_urls;
    private $oContent;
    private $oUserFeed;
    private $_cont_rids;
    private $segment;
    
    public function init()
    {
        $this->set_access(self::ACCESS_SELF , self::NOACCESS_REDIRECT );
    }
    public function initParam()
    {
        $this->page = abs($this->input('page' , 'g' , 1));
        $this->segment=abs($this->input('segment','g',1));
    }

    public function checkParam()
    {
        
    }
    public function main()
    {
        $uid = $this->__visitor['uid'];
        ml_tool_actionlog::add_other_action($this->__visitor['uid'] , ML_SINAACTCODE_VIEW_HOME_COMMENT);
        
        
        $oRds = new ml_model_rdsNotice();
        $aRs = $oRds->getNotice($uid);
        //清除提醒
        if($this->page == 1)
        {
            $oRds->clean_one_field($uid , ml_model_rdsNotice::NTCTYPE_ADDCOMMENT  );
        }
        //页面导航上的记数
        $cnt['comment']=intval($aRs[ml_model_rdsNotice::NTCTYPE_ADDCOMMENT  ]);
        $cnt['atme']=intval($aRs[ml_model_rdsNotice::NTCTYPE_ADDATME  ]);
        $cnt['atti']=intval($aRs[ml_model_rdsNotice::NTCTYPE_ADDATTITUDE  ]);
        
        $data = array();
        $begin=($this->page -1 )*($this->pagesize);
        $oComment= new ml_model_dbComment();
        $oComment->getComCountByUid($uid);
        $total=$oComment->get_data();
        $rs = $oComment->getCommentsByUid($uid ,$begin, $this->pagesize);
        if(!$rs)
            $this->redirect(ML_PAGE_SYSTEM_BUSY);
                
        $aRows = $oComment->get_data();

        
        

        //格式化数据
        foreach ($aRows as $key => &$value) {
            $aUid[] = $value['act_uid'];
            $aRid[] = $value['rid'];
        }

        $aNicks = ml_tool_nick::uids2nicks($aUid);
        $oContent = new ml_model_dbContent();
        $oContent->get_content_by_rids($aRid);
        $aRid2Con = Tool_array::format_2d_array($oContent->get_data() ,'rid', Tool_array::FORMAT_FIELD2ROW);

        foreach ($aRows as $key => &$value) {
            $value['content'] = ml_tool_formatContent::format_content($value['content']);
            $value['goods'] = $aRid2Con[$value['rid']];
            $value['act_nick'] = $aNicks[$value['act_uid']];
            $aHtml[] = ml_tool_template::parseModTpl($value , 'cmtMe');
        }
        




        $obizUser = ml_biz_user_getinfo::get_instance();
        $obizUser->initUser($uid,$uid);
        $arr = $obizUser->getUserArea();
        $data = array_merge($aRows,$arr);
        $data['PAGER'] = array(
                'total_page' => ceil($total/($this->pagesize)),
                'cur_page' => $this->page,
                'url' => '/message/comment/?page={*}'
            );
        $data['aHtml']=$aHtml;
        $data['cnt'] =$cnt;
        $data['title']='我收到的评论-美啦';
        $this->set_scope_var('$skilltags',$arr['skill_tags']);
        $this->page_output('user::commentMe',$data);    
    }
}
new commentme();